package org.journey.datasouece;

import lombok.extern.slf4j.Slf4j;

import java.util.Optional;

@Slf4j
public class DataSourceHolder {

    private static final ThreadLocal<String> dataSourceName = new ThreadLocal<>();

    public static void setDataSourceName(String dbName) {
        log.debug("now dbName:"+ getDataSourceName());
        dataSourceName.set(dbName);
        log.debug("after dbName:"+ getDataSourceName());
    }

    public static String getDataSourceName() {
        return Optional.ofNullable(dataSourceName.get()).orElse("");
    }

    public static void clearDataSourceName() {
        dataSourceName.remove();
    }

}
